Enhance Ozi reader and writer to allow waypoint colors to be preserved
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 1 Dec 2005 20:00:42 +0000 (20:00 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 1 Dec 2005 20:00:42 +0000 (20:00 +0000)
across a merge.

gpsbabel/defs.h
gpsbabel/ozi.c

index fdb1de893fe957cad2bfe1a8d820c742ca4bdaec..fb3e6c2cc247d92b11cbc8fa2fea752b2048f4a8 100644 (file)
@@ -212,6 +212,7 @@ fs_xml *fs_xml_alloc( long type );
 #define FS_AN1W 0x616e3177L
 #define FS_AN1L 0x616e316cL
 #define FS_AN1V 0x616e3176L
+#define FS_OZI 0x6f7a6900L
 
 /*
  * Misc bitfields inside struct waypoint;
index 3e2c919900952ed76918dcbfeb6a6f5c9dd0e5fe..af3b94a3d726bee31c2bb6a03717f7dd372660df 100644 (file)
 
 #define MYNAME        "OZI"
 
+typedef struct {
+       format_specific_data fs;
+       int fgcolor;
+       int bgcolor;
+} ozi_fsdata;
+
 
 static FILE *file_in;
 static FILE *file_out;
@@ -62,6 +68,37 @@ static gpsdata_type ozi_objective;
 
 static char *ozi_ofname = NULL;
 
+static void
+ozi_copy_fsdata(ozi_fsdata **dest, ozi_fsdata *src) 
+{
+       /* No strings to mess with.  Straight forward copy. */
+       *dest = (void *)xmalloc(sizeof(*src));
+       **dest = *src;
+       (*dest)->fs.next = NULL;
+}
+
+static void
+ozi_free_fsdata(void *fsdata)
+{
+       xfree(fsdata);
+}
+
+static
+ozi_fsdata *
+ozi_alloc_fsdata(void) 
+{
+       ozi_fsdata *fsdata = xcalloc(sizeof(*fsdata), 1);
+       fsdata->fs.type = FS_OZI;
+       fsdata->fs.copy = (fs_copy) ozi_copy_fsdata;
+       fsdata->fs.destroy = ozi_free_fsdata;
+
+       /* Provide reasonable defaults */
+       fsdata->fgcolor = 0;
+       fsdata->bgcolor = 65535;
+
+       return fsdata;
+}
+
 static void
 ozi_openfile(char *fname) {
     char *c, *tmpname;
@@ -321,7 +358,7 @@ wr_deinit(void)
 }
 
 static void
-ozi_parse_waypt(int field, char *str, waypoint * wpt_tmp)
+ozi_parse_waypt(int field, char *str, waypoint * wpt_tmp, ozi_fsdata *fsdata)
 {
     double alt;
 
@@ -356,9 +393,11 @@ ozi_parse_waypt(int field, char *str, waypoint * wpt_tmp)
         break;
     case 8:
         /* foreground color (0=black) */
+       fsdata->fgcolor = atoi(str);
         break;
     case 9:
         /* background color (65535=yellow) */
+       fsdata->bgcolor = atoi(str);
         break;
     case 10:
         /* Description */
@@ -562,7 +601,7 @@ data_read(void)
        }
 
         if ((strlen(buff)) && (strstr(buff, ",") != NULL)) {
-
+           ozi_fsdata *fsdata = ozi_alloc_fsdata();
             wpt_tmp = waypt_new();
 
             /* data delimited by commas, possibly enclosed in quotes.  */
@@ -584,7 +623,7 @@ data_read(void)
 
                     break;
                 case wptdata:
-                    ozi_parse_waypt(i, s, wpt_tmp);
+                    ozi_parse_waypt(i, s, wpt_tmp, fsdata);
                     break;
                 }
                 i++;
@@ -605,10 +644,13 @@ data_read(void)
                     waypt_free(wpt_tmp);
                 break;
             case wptdata:
-                if (linecount > 4)  /* skipping over file header */
+                if (linecount > 4) {  /* skipping over file header */ 
+                   fs_chain_add(&(wpt_tmp->fs), 
+                       (format_specific_data *) fsdata);
                     waypt_add(wpt_tmp);
-                else
+                } else {
                     waypt_free(wpt_tmp);
+               }
                 break;
             }
 
@@ -627,6 +669,15 @@ ozi_waypt_pr(const waypoint * wpt)
     double ozi_time;
     char *description;
     char *shortname;
+    int faked_fsdata = 0;
+    ozi_fsdata *fs = NULL;
+
+    fs = (ozi_fsdata *) fs_chain_find(wpt->fs, FS_OZI);
+
+    if (!fs) {
+       fs = ozi_alloc_fsdata();
+       faked_fsdata = 1;
+    }
 
     ozi_time = (wpt->creation_time / 86400.0) + 25569.0;
 
@@ -665,7 +716,7 @@ ozi_waypt_pr(const waypoint * wpt)
     fprintf(file_out,
             "%d,%s,%.6f,%.6f,%.5f,%d,%d,%d,%d,%d,%s,%d,%d,",
             index, shortname, wpt->latitude, wpt->longitude, ozi_time, 0,
-            1, 3, 0, 65535, description, 0, 0);
+            1, 3, fs->fgcolor, fs->bgcolor, description, 0, 0);
     if (wpt->proximity > 0)
        fprintf(file_out, "%.1f,", wpt->proximity);
     else
@@ -675,6 +726,9 @@ ozi_waypt_pr(const waypoint * wpt)
     xfree(description);
     xfree(shortname);
 
+    if (faked_fsdata) {
+       xfree(fs);
+    }
 }
 
 static void